package com.witmore.skyline.web.service;

import lombok.Getter;
import lombok.Setter;

/**
 * 地区查询服务
 *
 * @author 豆子高
 * @since 2025-10-22
 */
public interface RegionQueryService {

    /**
     * 根据省市区名称查询对应的adcode
     *
     * @param province 省份名称（必传）
     * @param city     城市名称（必传）
     * @param district 区县名称（可为空）
     * @return 地区编码信息
     */
    RegionCodeInfo getRegionCodeByNames(String province, String city, String district);

    /**
     * 地区编码信息
     */
    @Getter
    @Setter
    class RegionCodeInfo {
        private String provCode;
        private String province;
        private String cityCode;
        private String city;
        private String districtCode;
        private String district;
        private String fullName;
        private String originalAddress;

        public RegionCodeInfo() {
        }

        public RegionCodeInfo(String provCode, String province, String cityCode, String city, 
                             String districtCode, String district, String fullName) {
            this.provCode = provCode;
            this.province = province;
            this.cityCode = cityCode;
            this.city = city;
            this.districtCode = districtCode;
            this.district = district;
            this.fullName = fullName;
        }

        /**
         * 检查是否有效（至少有省或市信息）
         */
        public boolean isValid() {
            return (provCode != null && !provCode.isEmpty()) ||
                   (cityCode != null && !cityCode.isEmpty());
        }

        /**
         * 获取最精确的地区编码
         */
        public String getMostPreciseCode() {
            if (districtCode != null && !districtCode.isEmpty()) {
                return districtCode;
            }
            if (cityCode != null && !cityCode.isEmpty()) {
                return cityCode;
            }
            return provCode;
        }

        /**
         * 获取最精确的地区名称
         */
        public String getMostPreciseName() {
            if (district != null && !district.isEmpty()) {
                return district;
            }
            if (city != null && !city.isEmpty()) {
                return city;
            }
            return province;
        }
    }
}
